#include <climits>
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n;
    cin>>n;
    vector<int>num(n,0);
    vector<int>dp(n+1,0);
    for(int i=0;i<n;i++){
        cin>>num[i];     
    }
    int ret=INT_MIN;
    dp[0]=0;
    for(int i=1;i<=n;i++){
        dp[i]=max(num[i-1],dp[i-1]+num[i-1]);
        ret=max(ret,dp[i]);
    }
    cout<<ret<<endl;
    return 0;
}
